// 
// DotNetNuke?- http://www.dotnetnuke.com 
// Copyright (c) 2002-2012 
// by DotNetNuke Corporation 
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
// to permit persons to whom the Software is furnished to do so, subject to the following conditions: 
// 
// The above copyright notice and this permission notice shall be included in all copies or substantial portions 
// of the Software. 
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE. 
// 

using System;

using DotNetNuke;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
using DotNetNuke.Entities.Modules;

namespace YourCompany.Modules.DynamicText
{
    using global::DynamicText.Components.Presenters;
    using global::DynamicText.Components.Views;

    /// ----------------------------------------------------------------------------- 
    /// <summary> 
    /// The EditDynamicText class is used to manage content 
    /// </summary> 
    /// <remarks> 
    /// </remarks> 
    /// <history> 
    /// </history> 
    /// ----------------------------------------------------------------------------- 
    partial class EditDynamicText : PortalModuleBase, IEditDynamicText
    {
        protected EditDynamicTextPresenter Presenter = null;

        #region "Private Members"

        #endregion

        #region "Event Handlers"

        /// ----------------------------------------------------------------------------- 
        /// <summary> 
        /// Page_Load runs when the control is loaded 
        /// </summary> 
        /// <remarks> 
        /// </remarks> 
        /// <history> 
        /// </history> 
        /// ----------------------------------------------------------------------------- 
        protected void Page_Load(object sender, System.EventArgs e)
        {
            Presenter = new EditDynamicTextPresenter(this);
            SetupView();
            Presenter.OnViewLoad(Page.IsPostBack);
        }

        /// ----------------------------------------------------------------------------- 
        /// <summary> 
        /// cmdCancel_Click runs when the cancel button is clicked 
        /// </summary> 
        /// <remarks> 
        /// </remarks> 
        /// <history> 
        /// </history> 
        /// ----------------------------------------------------------------------------- 
        protected void cmdCancel_Click(object sender, EventArgs e)
        {
            Presenter.OnCancel();
        }

        /// ----------------------------------------------------------------------------- 
        /// <summary> 
        /// cmdUpdate_Click runs when the update button is clicked 
        /// </summary> 
        /// <remarks> 
        /// </remarks> 
        /// <history> 
        /// </history> 
        /// ----------------------------------------------------------------------------- 
        protected void cmdUpdate_Click(object sender, EventArgs e)
        {
            Presenter.OnUpdate();
        }

        /// ----------------------------------------------------------------------------- 
        /// <summary> 
        /// cmdDelete_Click runs when the delete button is clicked 
        /// </summary> 
        /// <remarks> 
        /// </remarks> 
        /// <history> 
        /// </history> 
        /// ----------------------------------------------------------------------------- 
        protected void cmdDelete_Click(object sender, EventArgs e)
        {
            Presenter.OnDelete();
        }

        #endregion

        #region "Private Methods"
        private void SetupView()
        {
            try
            {
                cmdDelete.Attributes.Add(
                    "onClick", "javascript:return confirm('" + Localization.GetString("DeleteItem") + "');");
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }

        #endregion

        #region "IEditTestDrivenDNNModule1"

        public bool AuditControlVisible
        {
            get { return ctlAudit.Visible; }
            set { ctlAudit.Visible = value; }
        }

        public bool DeleteButtonVisible
        {
            get { return cmdDelete.Visible; }
            set { cmdDelete.Visible = value; }
        }

        public string AuditCreatedByUser
        {
            set { ctlAudit.CreatedByUser = value; }
        }

        public string AuditCreatedDate
        {
            set { ctlAudit.CreatedDate = value; }
        }

        public string EditorContent
        {
            get { return txtContent.Text; }
            set { txtContent.Text = value; }
        }

        public System.Exception Exception
        {
            set { Exceptions.ProcessModuleLoadException(this, value); }
        }

        public int ItemId
        {
            get
            {
                int _itemId = 0;
                if ((Int32.TryParse(Request.QueryString["ItemId"], out _itemId)))
                {
                    return _itemId;
                }
                else
                {
                    return Null.NullInteger;
                }
            }
        }

        public bool SecurityViolation
        {
            set { Response.Redirect(Globals.NavigateURL()); }
        }

        public bool Redirect
        {
            set { Response.Redirect(Globals.NavigateURL()); }
        }

        public System.Collections.Hashtable Settings
        {
            get { return this.ModuleContext.Settings; }
        }

        #endregion

    }
}
